// Decompiled by Jad v1.5.7f. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   SCODataManager.java

package com.iphaeton.lms.course.scorm12.datamodel;

import com.iphaeton.lms.course.scorm12.DebugIndicator;
import com.iphaeton.lms.course.scorm12.datamodel.cmi.CMIComments;
import com.iphaeton.lms.course.scorm12.datamodel.cmi.CMICommentsFromLms;
import com.iphaeton.lms.course.scorm12.datamodel.cmi.CMICore;
import com.iphaeton.lms.course.scorm12.datamodel.cmi.CMIInteractions;
import com.iphaeton.lms.course.scorm12.datamodel.cmi.CMILaunchData;
import com.iphaeton.lms.course.scorm12.datamodel.cmi.CMIObjectives;
import com.iphaeton.lms.course.scorm12.datamodel.cmi.CMIRequest;
import com.iphaeton.lms.course.scorm12.datamodel.cmi.CMIStudentData;
import com.iphaeton.lms.course.scorm12.datamodel.cmi.CMIStudentPreference;
import com.iphaeton.lms.course.scorm12.datamodel.cmi.CMISuspendData;
import com.iphaeton.lms.course.scorm12.datamodel.cmi.DMErrorManager;
import java.io.PrintStream;
import java.io.Serializable;
import java.lang.reflect.*;
import java.util.StringTokenizer;

public class SCODataManager
    implements Serializable
{

    public CMICore getCore()
    {
        return core;
    }

    public CMISuspendData getSuspendData()
    {
        return suspend_data;
    }

    public CMILaunchData getLaunchData()
    {
        return launch_data;
    }

    public CMIComments getComments()
    {
        return comments;
    }

    public CMICommentsFromLms getCommentsFromLMS()
    {
        return comments_from_lms;
    }

    public CMIObjectives getObjectives()
    {
        return objectives;
    }

    public CMIInteractions getInteractions()
    {
        return interactions;
    }

    public CMIStudentData getStudentData()
    {
        return student_data;
    }

    public CMIStudentPreference getStudentPreference()
    {
        return student_preference;
    }

    public void setCore(CMICore inCore)
    {
        core = inCore;
    }

    public void setSuspendData(CMISuspendData inSuspendData)
    {
        suspend_data = inSuspendData;
    }

    public void setLaunchData(CMILaunchData inLaunchData)
    {
        launch_data = inLaunchData;
    }

    public void setComments(CMIComments inComments)
    {
        comments = inComments;
    }

    public void setCommentsFromLMS(CMICommentsFromLms inComments)
    {
        comments_from_lms = inComments;
    }

    public void setObjectives(CMIObjectives inObjectives)
    {
        objectives = inObjectives;
    }

    public void setInteractions(CMIInteractions inInteractions)
    {
        interactions = inInteractions;
    }

    public void setStudentData(CMIStudentData inStudentData)
    {
        student_data = inStudentData;
    }

    public void setStudentPreference(CMIStudentPreference inStudentPref)
    {
        student_preference = inStudentPref;
    }

    public SCODataManager()
    {
        core = new CMICore();
        suspend_data = new CMISuspendData();
        launch_data = new CMILaunchData();
        comments = new CMIComments();
        comments_from_lms = new CMICommentsFromLms();
        objectives = new CMIObjectives();
        interactions = new CMIInteractions();
        student_data = new CMIStudentData();
        student_preference = new CMIStudentPreference();
    }

    public String getValue(CMIRequest theRequest, DMErrorManager dmErrorMgr)
    {
        System.out.println("In SCODataManager::getValue");
        workingBaseCategory = theRequest.getBaseCategory();
        String result = new String("");
        if(workingBaseCategory.equals("_version"))
            result = "3.4";
        else
            result = processRequest(theRequest, dmErrorMgr);
        return result;
    }

    public void setValue(CMIRequest theRequest, DMErrorManager dmErrorMgr)
    {
        System.out.println("In SCODataManager::setValue");
        workingBaseCategory = theRequest.getBaseCategory();
        String result = processRequest(theRequest, dmErrorMgr);
    }

    private String processRequest(CMIRequest theRequest, DMErrorManager dmErrorMgr)
    {
        String result = new String("");
        String tmpClassName = convertString(workingBaseCategory);
        String className = "org.adl.datamodels.cmi.CMI" + tmpClassName;
        if(_Debug)
        {
            System.out.println("Class Name: " + className);
            System.out.println("Working Base Cat: " + workingBaseCategory);
        }
        try
        {
            Class c = Class.forName(className);
            try
            {
                Field tmpField = getClass().getField(workingBaseCategory);
                Class parameterTypes[] = {
                    theRequest.getClass(), dmErrorMgr.getClass()
                };
                Object arguments[] = {
                    theRequest, dmErrorMgr
                };
                try
                {
                    if(theRequest.isForASetRequest())
                    {
                        Method theMethod = c.getMethod("performSet", parameterTypes);
                        theMethod.invoke(tmpField.get(this), arguments);
                    } else
                    {
                        Method theMethod = c.getMethod("performGet", parameterTypes);
                        result = (String)theMethod.invoke(tmpField.get(this), arguments);
                    }
                }
                catch(NoSuchMethodException e)
                {
                    System.out.println(e);
                    e.printStackTrace();
                }
                catch(IllegalAccessException e)
                {
                    System.out.println(e);
                    e.printStackTrace();
                }
                catch(InvocationTargetException e)
                {
                    System.out.println(e);
                    e.printStackTrace();
                }
            }
            catch(NoSuchFieldException nsfe)
            {
                if(_Debug)
                {
                    System.out.println(nsfe);
                    System.out.println("Error - Data Model Element not Implemented");
                }
                dmErrorMgr.recNotImplementedError(theRequest);
            }
        }
        catch(ClassNotFoundException cnfe)
        {
            if(_Debug)
            {
                System.out.println(cnfe);
                System.out.println("Error - Data Model Element not implemented");
            }
            dmErrorMgr.recNotImplementedError(theRequest);
        }
        return result;
    }

    private String convertString(String theString)
    {
        StringTokenizer stk = new StringTokenizer(theString, "_", false);
        int total = stk.countTokens();
        String result;
        for(result = new String(""); stk.hasMoreTokens(); result = result.concat(fixWord(stk.nextToken())));
        return result;
    }

    private String fixWord(String wordToFix)
    {
        String result = new String("");
        String firstLetter = wordToFix.substring(0, 1);
        String restOfWord = wordToFix.substring(1);
        String ucFirstLetter = firstLetter.toUpperCase();
        result = ucFirstLetter.concat(restOfWord);
        return result;
    }

    private static final long serialVersionUID = 0xad9780978f76fe50L;
    private static boolean _Debug;
    public CMICore core;
    public CMISuspendData suspend_data;
    public CMILaunchData launch_data;
    public CMIComments comments;
    public CMICommentsFromLms comments_from_lms;
    public CMIObjectives objectives;
    public CMIInteractions interactions;
    public CMIStudentData student_data;
    public CMIStudentPreference student_preference;
    private String workingBaseCategory;
    private static final String CMI_VERSION = "3.4";
    private static final String DM_CLASSNAME = "org.adl.datamodels.cmi.CMI";

    static 
    {
        _Debug = DebugIndicator.ON;
    }
}
